package com.lottery.utils;

import java.util.ArrayList;
import java.util.List;

import com.lottery.beans.Ticket;

public class GetModeToCalculate {
	
	
	public static List<Ticket> dealDoubleChromosphere(List<Ticket> ticketList,String prizeNo){
		final List<String> winRedBallList=getRedBall(prizeNo);
		final String winBuleBall=getBuleBall(prizeNo);
		
		boolean buleBallResult =false;
		for(Ticket ti:ticketList){
			int redBallResult=0;
			String ticketNo=ti.getTicketNo();
			List<String> redBallList=getRedBall(ticketNo);
			String buleBall=getBuleBall(ticketNo);
			
			for (String ball : redBallList) {
	            if (winRedBallList.contains(ball)) {//如果存在球
	            	redBallResult++;
	            }
	        }
			
			if(winBuleBall.equals(buleBall)){
				buleBallResult=true;
			}
			
			ti.setLotteryResult(judgeLotteryResult(redBallResult,buleBallResult));
				
		}
		
		return ticketList;
		
	}
	
	/**
	 * 判断彩票中奖情况
	 * @author LIKANGDA934
	 * @date 2017年2月22日 下午8:41:10
	 * @version V1.0   
	 * @param redBallResult
	 * @param buleBallResult
	 * @return
	 */
	private static String judgeLotteryResult(int redBallResult, boolean buleBallResult) {
		if(redBallResult==6&&buleBallResult==true){
			return "1";
		}else if(redBallResult==6&&buleBallResult==false){
			return "2";
		}else if(redBallResult==5&&buleBallResult==true){
			return "3";
		}else if((redBallResult==5&&buleBallResult==false)||(redBallResult==4&&buleBallResult==true)){
			return "4";
		}else if((redBallResult==4&&buleBallResult==false)||(redBallResult==3&&buleBallResult==true)){
			return "5";
		}else if(buleBallResult==true){
			return "6";
		}else{
			return "0";
		}
	}

	/**
	 * 得到红球集合
	 * @author LIKANGDA934
	 * @date 2017年2月22日 下午8:41:34
	 * @version V1.0   
	 * @param ticketNo
	 * @return
	 */
	private static List<String> getRedBall(String ticketNo) {
		List<String> redBallList = new ArrayList<String>();
		if (ticketNo != null && ticketNo.length() == 14) {
			ticketNo = ticketNo.substring(0, 12);
			for (int i = 0; i < ticketNo.length(); i = i + 2) {
				redBallList.add(ticketNo.substring(i, i + 2));
			}
		}
		return redBallList;
	}
	
	/**
	 * 得到蓝球
	 * @author LIKANGDA934
	 * @date 2017年2月22日 下午8:41:52
	 * @version V1.0   
	 * @param ticketNo
	 * @return
	 */
	private static String getBuleBall(String ticketNo) {
		if (ticketNo != null && ticketNo.length() == 14) {
			return ticketNo.substring(12, 14);
		} else {
			return null;
		}

	}
	
	
}
